package com.winter.Controller;

import com.winter.model.IAtta;
import com.winter.model.UserInfo;
import com.winter.model.vo.request.BindingPhoneRequestVo;
import com.winter.model.vo.request.CheckUpdatePwdCodeRequestVo;
import com.winter.model.vo.request.OtherLogonRequestVo;
import com.winter.model.vo.request.UserLoginRequestVo;
import com.winter.model.vo.request.UserRegisterRequestVo;
import com.winter.service.UserService;
import com.winter.util.Result;
import com.winter.util.ResultCode;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/8/16.
 */
@RestController
@RequestMapping("v1/user")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 用户注册
     */
    @PostMapping("register")
    public Result userRegister(@RequestBody UserRegisterRequestVo registerRequestVo, HttpServletRequest request) {
        return userService.userRegister(registerRequestVo, request);
    }

    /**
     * 查看当前号码是否注册
     */
    @GetMapping("check_phone")
    public Result checkPhone(String phone) {
        UserInfo userInfo = userService.checkPhone(phone);
        if (userInfo != null) {
            return Result.failure(ResultCode.USER_HAS_EXISTED);
        } else {
            return Result.success();
        }

    }

    /**
     * 用户登录
     */
    @PostMapping("login")
    public Result login(@RequestBody UserLoginRequestVo userLoginRequestVo) {
        return userService.login(userLoginRequestVo);
    }


    /**
     * 第三方登录
     */
    @PostMapping("otherLogon")
    public Result otherLogon(@RequestBody OtherLogonRequestVo otherLogonRequestVo) {
        return userService.otherLogon(otherLogonRequestVo);
    }

    /**
     * 是否进行绑定第三方
     */
    @PostMapping("is_binding")
    public Result isBinding(@RequestBody OtherLogonRequestVo otherLogonRequestVo) {
        return userService.isBinding(otherLogonRequestVo);
    }

    /**
     * 第三方绑定手机号码
     */
    @PostMapping("binding")
    public Result binding(@RequestBody BindingPhoneRequestVo bindingPhoneRequestVo, HttpServletRequest request) {
        return userService.binding(bindingPhoneRequestVo, request);
    }


    /**
     * 验证码登录
     */
    @PostMapping("verify_login")
    public Result verificationLogin(@RequestBody UserLoginRequestVo userLoginRequestVo) {
        return userService.verificationLogin(userLoginRequestVo);
    }

    /**
     * 系统数据
     */
    @GetMapping("message")
    public Result message(String userNo, Integer pageSize, Integer pageNumber, Long userId) {
        return userService.message(userNo, pageSize, pageNumber, userId);
    }

    /**
     * 已读信息
     */
    @PutMapping("message_is_read")
    public Result messageIsRead(Long id) {
        return userService.messageIsRead(id);
    }

    /**
     * 我的个人资料
     */
    @GetMapping("my_profile")
    public Result myProfile(Long userId) {
        return userService.myProfile(userId);
    }

    /**
     * 我的报名
     */
    @GetMapping("my_apply")
    public Result myApply(String userNo, Integer pageSize, Integer pageNumber) {
        return userService.myApply(userNo, pageSize, pageNumber);
    }


    /**
     * 删除我的报名
     */
    @DeleteMapping("apply")
    public Result deleteApply(Long id) {
        return userService.deleteApply(id);
    }

    /**
     * 修改密码
     */
    @GetMapping("uppasswd")
    public Result updatePasswd(String userNo, String upPasswd) {
        return userService.updatePasswd(userNo, upPasswd);
    }


    @PostMapping("check_update_pwd_code")
    public Result checkCode(@RequestBody CheckUpdatePwdCodeRequestVo checkUpdatePwdCodeRequestVo) {
        return userService.checkUpdatePwdCode(checkUpdatePwdCodeRequestVo);
    }

    /**
     * 更换手机号
     */
    @GetMapping("upmobile")
    public Result updateMobile(String userNo, String mobile, String code) {
        return userService.updateMobile(userNo, mobile, code);
    }

    /**
     * 我的八卦
     */
    @GetMapping("my_gossip")
    public Result myGossip(Long userId, Integer pageSize, Integer pageNumber) {
        return userService.myGossip(userId, pageSize, pageNumber);
    }

    /**
     * 我的收藏智库
     */
    @GetMapping("my_collect_think_tank")
    public Result myCollectThinkTank(Long userId, Integer pageSize, Integer pageNumber, String type) {
        return userService.myCollectThinkTank(userId, pageSize, pageNumber,type);
    }



    /**
     * 我的收藏-公司
     */
    @GetMapping("my_collect_company")
    public Result myCollectCompany(String userNo, Integer pageSize, Integer pageNumber) {
        return userService.myCollectCompany(userNo, pageSize, pageNumber);
    }


    /**
     * 我的收藏报价-职位-资讯
     */
    @GetMapping("my_collect")

    public Result myCollect(String userNo, Integer type, Integer pageSize, Integer pageNumber) {
        return userService.myCollect(userNo, type, pageSize, pageNumber);
    }

    /**
     * 上传我的名片
     */
    @PostMapping("uploadCard")
    public Result uploadCard(@RequestBody IAtta iAtta) {
        return userService.uploadCard(iAtta);
    }

    /**
     * 修改用户头像
     */
    @PutMapping("userInfo")
    public Result updateHead(@RequestBody UserInfo userInfo) {
        return userService.updateHead(userInfo);
    }

    /**
     * 我的发布-报价
     */
    @GetMapping("my_pushQuote")
    public Result my_pushQuote(String userNo) {
        return userService.my_pushQuote(userNo);
    }

    /**
     * 删除报价
     */
    @DeleteMapping("delete/pushQuote")
    public Result deletePushQuote(Long id, Integer type) {
        return userService.deletePushQuote(id, type);
    }

    /**
     * 未读信息数量
     */
    @GetMapping("my_unread_num")
    public Result myUnreadNum(Long userId) {
        return userService.myUnreadNum(userId);
    }
}

